/**
 * Created by BigBi on 2017/4/10.
 */
var fs = require('fs');
var data = '';
var times = 0;

//step1 创建可读流
var readStream = fs.createReadStream('test.txt');

//step2 设置编码
readStream.setEncoding('UTF8');

//step3 处理流事件:data/end/error

readStream.on('data',function(chunk){
    data += chunk;
    times++;
    console.log('No.'+times,' data is:',data);
})

readStream.on('end',function(){
    console.log('数据读取完毕:',data);
});

readStream.on('error',function(err){
    console.log('数据读取失败：',err);
});


